package org.ncs;

import com.ncs.pojo.Product;
import com.ncs.util.MybatisUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author yinyin
 * @create 2021/07/22 下午 8:35
 */
public class EmpTest {


    @Test
    public void findAll(){
        SqlSession session=null;
        //获取session
        try {
            session = MybatisUtil.getSession();
            List<Emp> list = session.selectList("org.ncs.EmpMapper.findAll");
            for (Emp e:list
                 ) {
                System.out.println(e);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            MybatisUtil.closeSession(session);
        }
    }
    @Test
    public void test() throws IOException {
        InputStream inputStream = Resources.getResourceAsStream("source/mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = factory.openSession();
        System.out.println(session);
    }

}
